package housing.task5.dom;

import com.sun.org.apache.xerces.internal.parsers.DOMParser;
import housing.task1.actor.Renter;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: Linderhof
 * Date: 24.11.2010
 * Time: 15:37:51
 */
public class MainDOM {
    public static void main(String[] args) {
        DOMParser parser = new DOMParser();

        //get the DOM tree as a Document object:
        FileInputStream fis = null;
        try {
            fis = new FileInputStream("./src/main/resources/xml/RentersXML.xml");
            MyErrorHandler xmlHandler = new MyErrorHandler("logForDOM.txt");
            parser.parse(new InputSource(fis));
            Document doc = parser.getDocument();

            Element root = doc.getDocumentElement();
            ArrayList<Renter> renters = Analyzer.listBuilder(root);

            for (Renter r : renters) {
                System.out.println(r);
            }
        } catch (FileNotFoundException e) {
            System.out.println("Cant't found file RentersXML.xml!");
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (IOException ioe) {
            System.out.println("IOE in InputSource(fis");
            ioe.printStackTrace();
        } catch (SAXException saxe) {
            System.out.println("SAX exception!");
            saxe.printStackTrace();
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException ioe) {
                    System.out.println("Can't close fis!");
                }
            }
        }//finally
    }//void main()

}//class MainDOM
